package cn.dglydrpy.study.common.kafka;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * 消费者
 */
@Component
@Slf4j
public class KafkaConsumer {

    /**
     * 接收消息并处理
     * @param record  接收的消息记录
     */
    //@KafkaListener(topics = {"myTopic"})
    public void processMessage(ConsumerRecord record) {
        //1.接收消息
//        log.info("----------------- record =" + record);
        Optional<?> kafkaMessage = Optional.ofNullable(record.value());
        if (kafkaMessage.isPresent()) {
            Object message = kafkaMessage.get();
            //2.获取消息
//            log.info("------------------ message =" + message);
        }
    }
}
